<?php
class ClientDish extends CI_Controller{
	
	public function __construct(){
		parent::__construct();
		
		//check loggin
		if ($this->session->userdata('LoggedIn')){
			//load defense model
			$this->load->model('DishModel', 'dish', TRUE);
		}else{
			$arr = array('status' => 'fail', 'message' => 'error message here');
			echo json_encode($arr);
			exit();
		}
	}
	
	public function all_dish_detail(){
		$dishes = $this->dish->all_dish();
		
		if ($dishes == false){
			$arr = array('status' => 'fail', 'message' => 'error message here');
			echo json_encode($arr);
			exit();
		}else {
			$arr = array('status' => 'success', 'info' => $dishes);
			$json = json_encode($arr);
			print_r($json);
		}
	}
	
	public function dish_detail(){
		if (!isset($_GET['id']) || empty($_GET['id'])){
			$arr = array('status' => 'fail', 'message' => 'error message here');
			echo json_encode($arr);
			exit();
		}
		
		$dish_id = $_GET['id'];
		$dish = $this->dish->dish_detail($dish_id);
		
		if ($dish == false){
			$arr = array('status' => 'fail', 'message' => 'error message here');
			echo json_encode($arr);
			exit();
		}else {
			$arr = array('status' => 'success', 'info' => $dish);
			$json = json_encode($arr);
			print_r($json);
		}
	}
	
	public function all_dish_types(){
		$dishe_types = $this->dish->all_dish_types();
		
		if ($dishe_types == false){
			$arr = array('status' => 'fail', 'message' => 'error message here');
			echo json_encode($arr);
			exit();
		}else {
			$arr = array('status' => 'success', 'info' => $dishe_types);
			$json = json_encode($arr);
			print_r($json);
		}
	}
}